package com.teamb6.shop.controller.admin;

import com.teamb6.shop.domain.Admin;
import com.teamb6.shop.service.AdminService;
import com.teamb6.shop.util.Md5Util;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;


import java.security.Principal;


@Controller
@RequestMapping("/admin")
public class LoginController {
    @Autowired
    AdminService adminService;

    @RequestMapping("/login")
    public String adminLogin() {
        return "admin-login";
    }

    @GetMapping("/confirmLogin")
    public String confirmLogin() {

        return "login";
    }

    @RequestMapping("/success")
    public String loginsuccess(){
        return "admin-index";
    }



//    @RequestMapping("/confirmLogin")
//    public String confirmLogin(Admin admin, Model model, HttpServletRequest request){
//        admin.setPassword(Md5Util.MD5Encode(admin.getPassword(),"utf-8"));
//        Admin sadmin = adminService.findByName(admin);
//        if (sadmin == null){
//            model.addAttribute("errorMsg", "用户名或密码错误");
//            return "admin-login";
//        }else {
//            HttpSession session = request.getSession();
//            session.setAttribute("admin",sadmin);
//            return "redirect:/users/search";
//        }
//    }
//
//
//
//
//    @RequestMapping("/logout")
//    public String adminLogout(HttpServletRequest request){
//        HttpSession session = request.getSession();
//        session.removeAttribute("admin");
//        return "redirect:/admin/login";
//    }
}
